home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 9.0 KB | 337 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FormPrt.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Laurent Delamare
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Form.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef DIALOG_H
- #include "Dialog.h"
- #endif
-
- #ifndef FORMVIEW_H
- #include "FormView.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- #define kMainPresentation "ODF:Presentation:Form"
- #define kPasswordDialogPresentation "ODF:Presentation:Form:PasswordDialog"
- #define kInvalidDialogPresentation "ODF:Presentation:Form:InvalidDialog"
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfform
- #endif
-
- FW_DEFINE_AUTO(CFormPart)
-
- //========================================================================================
- // CFormPart class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormPart constructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::CFormPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fTextData(""),
- fIsForm(TRUE),
- fMainPresentation(NULL),
- fPwdDialogPresentation(NULL),
- fPictShape1(NULL),
- fPictShape2(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart destructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::~CFormPart()
- {
- delete fPictShape1;
- delete fPictShape2;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CFormPart::Initialize(Environment* ev) // Override
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register our Presentations
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);
- fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE);
-
- // ----- Init MenuBar -----
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
-
- // ----- Initialize pictures
- InitPicture(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::InitPicture
- //----------------------------------------------------------------------------------------
- // Keep picture shape with the part to share it among multiple frames
-
- void CFormPart::InitPicture(Environment* ev)
- {
- // Open the resource file for this shared library
- FW_CSharedLibraryResourceFile resFile(ev);
-
- #ifdef FW_BUILD_MAC
- FW_CPicture formPict1(resFile, kFormPict1);
- FW_CRect bounds;
- formPict1.GetPictBounds(bounds);
- fPictShape1 = FW_NEW(FW_CPictureShape, (formPict1, bounds));
-
- FW_CPicture formPict2(resFile, kFormPict2);
- formPict2.GetPictBounds(bounds);
- fPictShape2 = FW_NEW(FW_CPictureShape, (formPict2, bounds));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewPartContent
- //----------------------------------------------------------------------------------------
- // ODF Method
-
- FW_CContent* CFormPart::NewPartContent(Environment* ev)
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewDocumentWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* CFormPart::NewDocumentWindow(Environment* ev)
- {
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- FW_CRect pictRect;
- GetPictShape1()->GetRectangle(pictRect);
-
- FW_CRect screenBounds;
- ::FW_GetMainScreenBounds(screenBounds);
- screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
-
- return new FW_CWindow(ev,
- this,
- FW_CPart::gViewAsFrameToken,
- fMainPresentation, // presentation
- pictRect.Size() + sbSize, // interior size
- screenBounds.TopLeft(), // position
- FW_kDocumentWindow); // window style
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CFormPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage) // Override
- {
- FW_UNUSED(fromStorage);
- FW_CFrame* newFrame = NULL;
-
- if (presentation == fMainPresentation) {
- // Create the frame for the main presentation
- newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
- }
- else if (presentation == fPwdDialogPresentation) {
- // Create the frame for the dialog presentation, using a resource id
- newFrame = FW_NEW(CPwdDialogFrame,
- (ev, odFrame, presentation, this, kPasswordDialog));
- }
-
- return newFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Boolean menuHandled = TRUE;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- switch (id)
- {
- case cResetFormCommand:
- DoFormCommand(ev, id);
- break;
-
- case kODCommandAbout:
- ::FW_About(ev, this, kAbout);
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- if (hasMenuFocus)
- {
- // ToDo: should enable command only if the form has changed
- menuBar->EnableCommand(ev, cResetFormCommand, true);
- }
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoFormCommand
- //----------------------------------------------------------------------------------------
-
- void CFormPart::DoFormCommand(Environment* ev, ODCommandID id)
- {
- // This sample doesn't use a Content model yet. For now the "reset" command will
- // simply erase the text in the edit-fields of each frame
-
- FW_CPresentationFrameIterator iter(ev, fMainPresentation);
- for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
- {
- CFormView* formView = (CFormView*) frame->GetContentView(ev);
- formView->ResetData(ev);
- }
-
- #if 0
- // [LSD] PartMaker-generated code, not used yet because we don't have a content model
-
- // Mark the document as changed so it can be saved
- Changed(ev);
-
- // Mark the display frame as changed, so that containing parts can update links
- fMainPresentation->ContentUpdated(ev);
-
- // Force all frames to be redrawn
- fMainPresentation->Invalidate(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::GetResourceString
- //----------------------------------------------------------------------------------------
-
- void CFormPart::GetResourceString(Environment* ev,
- FW_ResourceId multiStringId,
- FW_ResourceId stringId,
- FW_CString& string)
- {
- // ----- Open the resource file for this shared library -----
- FW_CSharedLibraryResourceFile resFile(ev);
-
- // ----- Read the string from the resource file -----
- ::FW_LoadStringByID(ev, resFile, multiStringId, MULTISTRINGRES, stringId, string);
- }
-
-